package stream;

import pojo.UserInfo;

import java.util.ArrayList;
import java.util.function.Supplier;

/**
 * 匹配单个、所有元素
 */
public class AnyMatchAndAllMatch {
    public static void main(String[] args) {
        ArrayList<UserInfo> list = new ArrayList();
        UserInfo user = new UserInfo(1, "张三", 1);
        list.add(user);
        list.add(new UserInfo(2, "李四", 2));
        list.add(new UserInfo(3, "王五", 3));
        list.add(new UserInfo(3, "赵六", 4));
        // 注意比较的是 地址值
        boolean anyMatch = list.stream().anyMatch(userInfo -> user == userInfo);
        System.out.println("AnyMatch结果：" + anyMatch);
        boolean allMatch = list.stream().allMatch(userInfo -> user == userInfo);
        System.out.println("AllMatch结果：" + allMatch);
        mapperService();
    }


    public static Integer 模拟操作_插入数据(){
        return 1;
    }
    public static void mapperService() {

        boolean res = operateDB(() -> 模拟操作_插入数据());
        System.out.println(res);
    }

    public static boolean operateDB(Supplier<Integer> dbRes) {
        if (dbRes.get() != null && dbRes.get() > 0) {
            return true;
        } else {
            return false;
        }
    }

}
